<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<style>
    input.error{
        border:1px solid red;
    }
    span.error{
        padding-top:10px;
        color: #f00;
        font-size:12px;
    }
    span.rate-box{
        float: left;
        line-height: 2.6;
    }
</style>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>新增等级</h5>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">等级名称</label>
                            <div class="col-sm-6">
                                <input type="text" name="grade_name" class="form-control">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">一级佣金比例</label>
                            <div class="col-sm-6">
                                <input type="text" name="one_level_rate" class="form-control">
                            </div>
                            <span class="rate-box">%</span>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">二级佣金比例</label>
                            <div class="col-sm-6">
                                <input type="text" name="two_level_rate" class="form-control">
                            </div>
                            <span class="rate-box">%</span>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">三级佣金比例</label>
                            <div class="col-sm-6">
                                <input type="text" name="three_level_rate" class="form-control">
                            </div>
                            <span class="rate-box">%</span>
                            <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                        </div>
                        <div class="hr-line-dashed"></div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">分销商升级条件:</label>
                            <div class="col-sm-6">
                                <label class="radio-inline"><input type="radio" name="upgrade" value="0" checked="checked">默认等级</label>
                                <label class="radio-inline"><input type="radio" name="upgrade" value="1">邀请人数</label>
                                <label class="radio-inline"><input type="radio" name="upgrade" value="2">邀请人消费金额</label>
                                <label class="radio-inline"><input type="radio" name="upgrade" value="3">购买指定商品</label>
                            </div>
                        </div>
                        
                        <div class="form-group count-box" style="display: none">
                            <label class="col-sm-2 control-label">邀请人数达到:</label>
                            <div class="col-sm-6">
                                <input type="text" name="user_count" class="form-control">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px;padding-left: 0;">人</label>
                        </div>

                        <div class="form-group amount-box" style="display: none">
                            <label class="col-sm-2 control-label">邀请人消费金额达到:</label>
                            <div class="col-sm-6">
                                <input type="text" name="consume_amount" class="form-control">
                            </div>
                            <label class="col-sm-1" style="padding-top:7px;padding-left: 0;">元</label>
                        </div>

                        <div class="form-group goods-box" style="display: none">
                            <label class="col-sm-2 control-label">选择商品信息:</label>
                            <div class="col-sm-6">
                            <button type="button" class="btn btn-success" onclick="selectGoods();">选择商品信息</button>
                            </div>
                        </div>
                        
                        <div class="form-group goods-box" style="display: none">
                            <label class="col-sm-2 control-label">已选商品信息:</label>
                            <div class="col-sm-8">
                                <table class="table table-hover table-bordered">
                                    <thead class="biaoge">
                                        <tr>
                                            <th style="width:30%">商品名称</th>
                                            <th style="width:20%">缩略图</th>
                                            <th style="width:15%">所属分类</th>
                                            <th style="width:20%">金额</th>
                                            <th style="width:15%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="goods_list">
                                       
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">状态:</label>
                            <div class="col-sm-6">
                                <label class="radio-inline"><input type="radio" name="status" checked="checked" value="1">启用</label>
                                <label class="radio-inline"><input type="radio" name="status" value="0">停用</label>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit" id="doSubmit">保存内容</button>
                                <button class="btn btn-primary" type="button" onclick="goBack();">返回</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
<script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>
<!-- iCheck -->
<script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
<script src="__PUBLIC__/admin/js/common/ajax.js"></script>
<script type="text/javascript">

    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });

    var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
    $('#form').validate({
        errorElement : 'span',
        debug: true,//只验证不提交表单
        //layer ajax提交表单
        submitHandler:function(){
            // 序列化 表单数据 后提交 ，太简洁了
            post("{:url('DistributionGrade/add')}",'POST',$('#form').serialize(),1);
            return false;
        },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法

        rules:{
            grade_name:{required:true},
            one_level_rate:{required:true,number:true},
            two_level_rate:{required:true,number:true},
            three_level_rate:{required:true,number:true}
        },

        messages:{
            grade_name:{required:icon+'必填'},
            one_level_rate:{required:icon+'必填',number:icon+'请填写数字'},
            two_level_rate:{required:icon+'必填',number:icon+'请填写数字'},
            three_level_rate:{required:icon+'必填',number:icon+'请填写数字'}
        }
    });
    
    $('input[type=radio][name=upgrade]').change(function(){
        var val = this.value;
        if (val == 1) {
            $('.count-box').show();
            $('.amount-box').hide();
            $('.goods-box').hide();
        } else if (val == 2) {
            $('.amount-box').show();
            $('.count-box').hide();
            $('.goods-box').hide();
        } else if (val == 3) {
            $('.goods-box').show();
            $('.count-box').hide();
            $('.amount-box').hide();
        } else {
            $('.count-box').hide();
            $('.amount-box').hide();
            $('.goods-box').hide();
        }
    });
    
    function selectGoods(){
        var goods_id = new Array();
        //过滤选择重复信息
        $('input[name*=goods_id]').each(function(i,o){
            goods_id.push($(o).val());
        });

        var goodsurl = "/{$Request.module}/hdgoods/lst/goods_id/"+goods_id;

        layer.open({
            type: 2,
            title: '选择商品信息',
            shadeClose: true,
            shade: 0.3,
            area: ['70%', '80%'],
            content: goodsurl
        });
    }

    function call_backgoods(table_html){
        layer.closeAll('iframe');
        $('#goods_list').html(table_html);
    }
    
    function yichu(obj){
        $(obj).parent().parent().remove();
    }
    
    function cl(){
        location.href = "{:url('DistributionGrade/lst')}";
    }
</script>

</body>
</html>
